// components/test/test.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    data:{
      type:String,
      value: {
        title: '',
        describe:''
      },
      activeKey:0
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    titleList: [{text:'摄影师',value:'a'}],
    value1: 'a',
    activeKey:0
  },

  /**
   * 组件的方法列表
   */
  lifetimes: {
    attached: function() {
      // 页面加载时调用 getpicturemanList 方法发送请求
      this.getpicturemanList();
    }
  },
  methods: {
    showPopup() {
      this.setData({ show: true });
    },
    onClose() {
      this.setData({ show: false });
    },
    goCompany() {
      wx.redirectTo({
        url: "../company/company",
      });
    },
    goIndex() {
      wx.redirectTo({
        url: "../index/index",
      });
    },
    goPicture() {
      wx.navigateTo({
        url: "../picture/picture",
      });
    },
    goProduction(value) {
      console.log('看啊可能',value);
      let word = value._relatedInfo.anchorTargetText;
      // 使用正则表达式替换换行符为空字符串
      let noLineBreaks = word.replace(/ /g, "");
      // 使用trim方法去除首尾空白字符
      let pureString = noLineBreaks.trim();
      wx.navigateTo({
        url: "../production/production?name=" + pureString,
      });
    },
    goCameraman() {
      wx.redirectTo({
        url: "../cameraman/cameraman",
      });
    },
    goVideo() {
      wx.redirectTo({
        url: "../video/video",
      });
    },
    goSubscribe() {
      wx.redirectTo({
        url: "../company/company?subscribe=true",
      });
    },
    getpicturemanList() {
      wx.request({
        url: 'https://yingshi.saas.youyougoo.com/app-user-api/yingshi/photographer/page',
        method: 'GET',
        header: {
          "tenant-id": "155",
          "Authorization": "Bearer test131",
        },
        data: {
          pageNo: 1,
          pageSize: 100,
        },
        success: (res) => {
          let titleList = this.data.titleList
          // 需要先映射数组，然后使用 this.setData() 更新页面数据
          const formattedList = res.data.data.list.map(item => {
              return {
                text: item.name,
                value: item.id,
                status: item.status
              };
          });
          formattedList.forEach(item => {
            if(item.status !== 2){
              titleList.push(item); // 使用 push 方法添加每一项
            }
          });
          // 更新 setData，此时 titleList 应该是一个字符串键
          this.setData({
            titleList: titleList, // 使用格式化后的列表数据更新 titleList
          });
        },
        fail: (err) => {
          console.error(err);
        }
      });
    }
  },
});
